package core.collection.mylist;

import core.collection.bean.Student;

import java.util.ArrayList;
import java.util.List;

/**
 * List集合存储学生对象并遍历
 *
 * @author
 * @create 2018-12-23 9:02
 **/
public class mylist_2_List_Iterator {
    /**
     * 向List集合中存储学生对象
     * 用size()和get()方法结合使用遍历
     * @param args
     */
    public static void main(String[] args){
        List list = new ArrayList();
        list.add(new Student("tom",23));
        list.add(new Student("jac",23));
        list.add(new Student("jack",23));
        for(int i=0;i<list.size();i++){
            //System.out.println(list.get(i));
            //通过索引获取每个元素
            Student s = (Student)list.get(i);
            System.out.println(s.getName()+".."+s.getAge());
        }
    }
}
